home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / time.h < prev    next >
C/C++ Source or Header  |  1992-01-18  |  2KB  |  47 lines

  1.                                 // Chapter 6 - Program 10
  2.  
  3. // This is probably the minimum usable time class, but is intended as
  4. //  an illustration of a class rather than to build an all inclusive
  5. //  class for future use.  Each student can develop his own to suit
  6. //  his own taste.
  7.  
  8. #ifndef TIME_H
  9. #define TIME_H
  10.  
  11. class time_of_day {
  12. protected:
  13.    int hour;                   // 0 through 23
  14.    int minute;                 // 0 through 59
  15.    int second;                 // 0 through 59
  16.    static char format;         // Format to use for output
  17.    static char out_string[25]; // Format output area
  18.  
  19. public:
  20.          // Constructor - Set time to current time and format to 1
  21.    time_of_day(void);
  22.    time_of_day(int H) {hour = H; minute = 0; second = 0; };
  23.    time_of_day(int H, int M) {hour = H; minute = M; second = 0; };
  24.    time_of_day(int H, int M, int S) {hour = H;
  25.                                            minute = M; second = S; };
  26.  
  27.          // Set the time to these input values
  28.          //  return = 0 ---> data is valid
  29.          //  return = 1 ---> something is out of range
  30.    int set_time(void);
  31.    int set_time(int hour_in);
  32.    int set_time(int hour_in, int minute_in);
  33.    int set_time(int hour_in, int minute_in, int second_in);
  34.  
  35.          // Select string output format
  36.    void set_time_format(int format_in) { format = format_in; };
  37.  
  38.          // Return an ASCII-Z string depending on the stored format
  39.          //   format = 1    13:23:12
  40.          //   format = 2    13:23
  41.          //   format = 3     1:23 PM
  42.    char *get_time_string(void);
  43.  
  44. };
  45.  
  46. #endif
  47.